package com.newcapec.modules.pass.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.R;
import com.newcapec.modules.pass.entity.VenueInfoEntity;
import com.newcapec.modules.pass.service.VenueInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 场馆信息
 *
 * @author steven
 * @email wangsen127@163.com
 * @date 2021-12-14 10:11:28
 */
@RestController
@RequestMapping("pass/venueinfo")
public class VenueInfoController {
    @Autowired
    private VenueInfoService venueInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("pass:venueinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = venueInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表全部
     */
    @GetMapping("/listAll")
    @RequiresPermissions("pass:venueinfo:list")
    public R listAll(@RequestParam Map<String, Object> params){
        Object customerId = params.get("customerId");
        QueryWrapper<VenueInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(customerId!=null, "customer_id", customerId);
        List<VenueInfoEntity> list = venueInfoService.list(queryWrapper);

        return R.ok().put("list", list);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("pass:venueinfo:info")
    public R info(@PathVariable("id") Long id){
		VenueInfoEntity venueInfo = venueInfoService.getById(id);

        return R.ok().put("venueInfo", venueInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("pass:venueinfo:save")
    public R save(@RequestBody VenueInfoEntity venueInfo){
		venueInfoService.save(venueInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresPermissions("pass:venueinfo:update")
    public R update(@RequestBody VenueInfoEntity venueInfo){
		venueInfoService.updateById(venueInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("pass:venueinfo:delete")
    public R delete(Long[] ids){
		venueInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
